package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties("handler")
public class Daily extends BaseDomain{
    public static final Integer STATE_RELEASE = 0; //发布
    public static final Integer STATE_TEMP = 1; //草稿
    public static final Integer STATE_RECOMMEND = 2; //推荐

    private String title;// 标题

    private String subTitle;//副标题

    private Integer likenum=0;//点赞数

    private Integer state;//状态

    private String coverUrl;//封面图片

    private DailyContent dailyContent;//日报内容

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date schedule;//计划时间

    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("title",title);
        map.put("id",id);
        map.put("subTitle",subTitle);
        map.put("likenum",likenum);
        map.put("coverUrl",coverUrl);
        map.put("schedule",schedule);
        map.put("state",state);
        return JSON.toJSONString(map);
    }

    public String getStateName() {
        String str = "发布";
        if (state == STATE_TEMP) {
            str = "草稿";
        }else if(state ==STATE_RECOMMEND){
            str = "推荐";
        }
        return str;
    }
}